import React, {Component} from 'react';
import './input.scss';

/**
 * 输入框，可接受 class
 */
class Block extends Component {
    constructor(props) {
        super(props);
        this.state = {
            className: '',
            weight: 0,
        };
        this.onClick = this.onClick.bind(this, this.props.i, this.props.j);
    }

    onClick(i, j) {
        this.setClassName('bgc-black');
        this.props.onClick(i, j, this, this.state.weight);
    }

    setClassName(className) {
        this.setState({
            className: className,
        });
    }

    setWeight(weight) {
        this.setState({
            weight: weight,
        });
    }

    render() {
        return (
            <button className={`block ${this.state.className}`}
                    onClick={this.onClick} >{this.state.weight}</button>
        );
    }
}

export default Block;
